// 配置数据库相关信息
let mysql = require('mysql')

let pool = mysql.createPool({
        host: '120.27.2.122',
        user: 'Stu_Dorm_Mgmt',
        password: '2ZLPb7a26c7Fzfmm',
        database: 'stu_dorm_mgmt'
    })
    //定义通用的查询接口并将其导出
var query = function(sql, values, callback) {
    pool.getConnection(function(err, conn) {
        if (err) {
            callback(err, null, null);
        } else {
            conn.query(sql, values, function(qerr, results, fields) {
                //释放连接
                conn.release();
                //事件驱动回调
                callback(qerr, results, fields);
            });
        }
    });
};
module.exports = query;